﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using POSSystem.BLL;

namespace WebUI.Controls
{
    public partial class PurchaseViewerCtrl : BaseEditControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);

            if (!IsPostBack)
            {
                lblCompany.Text = Branches.CurrentBranch.s_Name;
                lblAddress.Text = Branches.CurrentBranch.s_Address;
                lblABN.Text = Branches.CurrentBranch.s_ABN;
                lblFax.Text = Branches.CurrentBranch.s_Fax;
                lblPhone.Text = Branches.CurrentBranch.s_Phone;
                litFooter.Text = SysVars.PurchaseFooter;
            }
        }

        public void LoadPurchaseByID(int poID)
        {
            View_PurchaseOrders po = View_PurchaseOrders.GetPurchaseOrderByID(poID);

            if (po.RowCount < 0)
                return;

            if (po.s_CreatedDate != "")
                lblDate.Text = po.CreatedDate.ToString(SysVars.DateFormat);

            lblPurchaseNo.Text = po.PurchaseOrderNo;
            divPurchaseNo.InnerHtml = Utilities.GenerateBarCode(po.InvoiceNo);

            poDetails.ShowFooter = false;
            poDetails.SourceObject = View_PrintPurchaseDetails.GetPurchaseDetailsByPOID(poID);
            poDetails.UpdateTotalAmt();
            poDetails.Refresh();
            poDetails.Columns[3].Visible = false;

            lblTotalAmt.Text = string.Format("{0:C}", po.TotalAmount);
            lblTotalGST.Text = string.Format("{0:C}", po.GSTTotalAmount);

            lblSupllier.Text = po.s_SupplierName;
            if (po.s_AccountNo != "")
                lblSupllier.Text += " (" + po.AccountNo + ")";

            lblSupllierABN.Text = po.ABN;
            lblSupllierAddress.Text = po.Address;
            lblSupllierFax.Text = po.Fax;
            lblSupllierPhone.Text = po.Phone;
        }
    }
}